text: Avoid a crash
authorTimm Bäder <mail@baedert.org>
Fri, 16 Oct 2020 19:55:37 +0000 (21:55 +0200)
committerTimm Bäder <mail@baedert.org>
Thu, 22 Oct 2020 15:46:34 +0000 (17:46 +0200)
Calculate the "was previous focus in a child widget" condition before
chaining up into grab_focus, to a void that unreffing the prev_focus
widget.

gtk/gtktext.c

index 8f2745caf61f952af16dad4b360df911235a0f72..ceb7addbfdc337396b4c34fa0a863669b9edb36a 100644 (file)
@@ -3228,14 +3228,15 @@ gtk_text_grab_focus (GtkWidget *widget)
   GtkTextPrivate *priv = gtk_text_get_instance_private (self);
   gboolean select_on_focus;
   GtkWidget *prev_focus;
+  gboolean prev_focus_was_child;
 
   prev_focus = gtk_root_get_focus (gtk_widget_get_root (widget));
+  prev_focus_was_child = prev_focus && gtk_widget_is_ancestor (prev_focus, widget);
 
   if (!GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self)))
     return FALSE;
 
-  if (priv->editable && !priv->in_click &&
-      !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget)))
+  if (priv->editable && !priv->in_click && !prev_focus_was_child)
     {
       g_object_get (gtk_widget_get_settings (widget),
                     "gtk-entry-select-on-focus",